package com.ts.session.controller;

import com.ts.common.entity.ResponseResult;
import com.ts.common.page.PageData;
import com.ts.common.validator.ValidatorUtils;
import com.ts.common.validator.group.AddGroup;
import com.ts.common.validator.group.DefaultGroup;
import com.ts.session.dto.SessionDTO;
import com.ts.session.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 
 *
 * @author Ywl 193363874@qq.com
 * @since 1.0.0 2023-07-15
 */
@RestController
@RequestMapping("/session")
public class SessionController {
    @Autowired
    private SessionService sessionService;

    @GetMapping("/page")
    public ResponseResult page(@RequestParam Map<String, Object> params){
        PageData<SessionDTO> page = sessionService.page(params);

        return ResponseResult.success(page);
    }

    @GetMapping("/{id}")
    public ResponseResult get(@PathVariable("id") Long id){
        SessionDTO data = sessionService.get(id);

        return ResponseResult.success(data);
    }

    @PostMapping
    public ResponseResult save(@RequestBody SessionDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        sessionService.save(dto);

        return ResponseResult.success();
    }
}